<template>
  <div>
    <el-table
      ref="tableRef"
      :class="'mgt-15 '+(border?'clearBorder':'')"
      :size="size"
      :data="tableData"
      :height="height"
      :row-key="rowKey"
      :border="border"
      :highlight-current-row="highlightCurrentRow"
      stripe
      :span-method="spanMethod"
      :header-cell-style="{color: '#3280FC',background: '#F2F8FF', 'text-align': headerCellStyle }"
      :cell-style="{ 'text-align': cellStyle }"
      @current-change="handleTableCurrentChange"
      @selection-change="selectionChange"
    >
      <slot name="_front" />
      <el-table-column
        v-for="(item, i) in columns"
        :key="i"
        show-overflow-tooltip
        :align="item.align || 'left'"
        :label="item.label"
        :prop="item.prop"
        :min-width="item.minWidth"
        :width="item.width"
        :resizable="resizable"
      />
      <slot name="_file" />
      <slot name="_end" />
    </el-table>
    <el-pagination
      v-if="paginationFlag"
      class="mgt-10"
      :style="{ textAlign: pagination && pagination.align || 'right' }"
      :current-page="pagination && pagination.currentPage"
      :page-sizes="[5, 10, 20, 50, 100]"
      :page-size="pagination && pagination.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>

export default {
	name: 'DetailList',
	props: {
		size: {
			type: String,
			default: 'default',
		},
		tableData: {
			type: Array,
			default: () => [],
		},
		pagination: {
			type: Boolean || Object,
			default: false
		},
		paginationFlag: {
			type: Boolean,
			default: true
		},
		columns: {
			type: Array,
			default: () => []
		},
		hiddenTitle: {
			type: Boolean,
			default: false
		},
		total: {
			type: Number,
			default: 0
		},
		height: {
			type: String || Object,
			default: () => null
		},
		rowKey: {
			type: String,
			default: ''
		},
		highlightCurrentRow: {
			type: Boolean,
			default: false
		},
		spanMethod: {
			type: Function,
			default: () => {}
		},
		border: {
			type: Boolean,
			default: false
		},
		resizable: {
			type: Boolean,
			default: false
		},
		cellStyle: {
			type: String,
			default: 'center'
		},
		headerCellStyle: {
			type: String,
			default: 'center'
		},
	},
	data() {
		return {
			selectionList: []
		};
	},
	methods: {
		handleSizeChange(a) {
			this.pagination.pageSize = a;
			this.pagination.currentPage = 1;
			this.$emit('pageChange');
		},
		handleCurrentChange(a) {
			this.pagination.currentPage = a;
			this.$emit('pageChange');
		},
		selectionChange(val) {
			this.selectionList = val;
			this.$emit('selection-change', val);
		},
		clearSelection() {
			this.$refs.tableRef.clearSelection();
		},
		toggleRowSelection(rows) {
			if(rows) {
				rows.forEach(row=>{
					this.$refs.tableRef.toggleRowSelection(row);
				});
				return;
			}
			this.$refs.tableRef.clearSelection();
		},
		handleTableCurrentChange(val) {
			this.$emit('current-change', val);
		},
		doLayout() {
			this.$refs.tableRef.doLayout();
		}
	}
};
</script>
<style scoped>
._detail table thead tr th{
    background-color: #F2F8FF!important;
	color: #333;
}
.clearBorder{
    border-right: none!important;
}
/deep/ .el-table__header-wrapper thead th {
    background-color: white;
}
/deep/ .el-table__header-wrapper thead th {
    color: #fff;
}
</style>
